import React from 'react'
import {
    Route,
    Redirect,
    Switch
} from 'react-router-dom'
import Bundle from './Bundle'

import TopicList from 'bundle-loader?lazy&name=list!../views/topic-list/index'
import TopicDetail from 'bundle-loader?lazy&name=detail!../views/topic-detail/index'

const createComponent = component => () =>(
    <Bundle load={component}>
        {Component => <Component />}
    </Bundle>
)

export default () => (
    <Switch>
        <Route path="/" render={() => <Redirect to="/list" />} exact/>
        <Route path="/list" component={createComponent(TopicList)} />
        <Route path="/detail" component={createComponent(TopicDetail)}/>
    </Switch>
)